package com.zhengxiang.onlinexamination.controller;

import com.zhengxiang.onlinexamination.base.AjaxResult;
import com.zhengxiang.onlinexamination.base.BaseController;
import com.zhengxiang.onlinexamination.entity.Setting;
import com.zhengxiang.onlinexamination.service.SettingService;
import com.zhengxiang.onlinexamination.utils.oss.OSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/file")
public class FileController extends BaseController {

    @Autowired
    private SettingService settingService;

    /*上传人员头像*/
    @PostMapping("/uploadUserHead")
    public AjaxResult uploadUserHead( MultipartFile file) throws IOException {
        Setting setting = settingService.querySetting(3,3);
        OSSUtils.putObject(file.getInputStream(),file.getOriginalFilename(),setting.getSetVal());
        String objectUrl = OSSUtils.getObjectUrl(setting.getSetVal(), file.getOriginalFilename());
        return AjaxResult.success().put("userHeadUrl",objectUrl);
    }

}
